package is.progetto2.activity;

public class Bind implements Comparable<Bind> {

	private Job job1=null, job2=null;
	private BindType bind1=null,bind2=null,bind3=null;
	
	protected Bind(){
		
	}

	public Job getJob1() {
		return job1;
	}

	public void setJob1(Job job1) {
		if(job1==null){
			throw new IllegalArgumentException();
		}
		this.job1 = job1;
		inv();
	}

	private void inv() {
		if(job1==job2){
			throw new IllegalStateException();
		}
	}

	public Job getJob2() {
		return job2;
	}

	public void setJob2(Job job2) {
		if(job2==null){
			throw new IllegalArgumentException();
		}
		this.job2 = job2;
		inv();
	}

	public BindType getBind1() {
		return bind1;
	}

	public void setBind1(BindType bind1) {
		if(bind1.equals(BindType.FIRST) || bind1.equals(BindType.AFTER)){
			throw new IllegalArgumentException();
		}
		this.bind1 = bind1;
	}

	public BindType getBind2() {
		return bind2;
	}

	public void setBind2(BindType bind2) {
		if(bind2.equals(BindType.BEGIN) || bind2.equals(BindType.END)){
			throw new IllegalArgumentException();
		}
		this.bind2 = bind2;
	}

	public BindType getBind3() {
		return bind3;
	}

	public void setBind3(BindType bind3) {
		if(bind3.equals(BindType.FIRST) || bind3.equals(BindType.AFTER)){
			throw new IllegalArgumentException();
		}
		this.bind3 = bind3;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + bind1.hashCode();
		result = prime * result + bind2.hashCode();
		result = prime * result + bind3.hashCode();
		result = prime * result + ((job1 == null) ? 0 : job1.hashCode());
		result = prime * result + ((job2 == null) ? 0 : job2.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Bind other = (Bind) obj;
		if (bind1 != other.bind1)
			return false;
		if (bind2 != other.bind2)
			return false;
		if (bind3 != other.bind3)
			return false;
		if (job1 == null) {
			if (other.job1 != null)
				return false;
		} else if (!job1.equals(other.job1))
			return false;
		if (job2 == null) {
			if (other.job2 != null)
				return false;
		} else if (!job2.equals(other.job2))
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "("+bind1+", "+job1+", "+bind2+", "+bind3+", "+job2+")";
	}

	@Override
	public int compareTo(Bind o) {
		int c = bind1.compareTo(o.bind1);
		if (c == 0) {
			c = Integer.compare(job1.getId(), o.job1.getId());
			if (c == 0) {
				c = bind2.compareTo(o.bind2);
				if (c == 0) {
					c = bind3.compareTo(o.bind3);
					if (c == 0) {
						c = Integer.compare(job2.getId(), o.job2.getId());
					}
				}
			}
		}
		return c;
	}
}
